#include "mainwindow.h"
#include "MysqlController.h"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QApplication>
#include <QDebug>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{

    QApplication a(argc, argv);
    MainWindow w;
    w.show();


    MysqlController MC;  //数据库有关操作的函数库

    MC.ClearOrders();


    //注册并实名，添加三个亲属
    MC.Register("cxk","123456",0);
    MC.AddRelatives("cxk","cxk_wife","4106xxxxxxxxxxxxxx");
    MC.AddRelatives("cxk","cxk_son","4106xxxxxxxxxxxxxx");
    MC.AddRelatives("cxk","cxk_bro","4106xxxxxxxxxxxxxx");

    MC.ClearOrders();

    //查直达，中转，往返，多程四种航线
    MC.FindFlights("沈阳","西安","Mon");
    MC.FindTrans("珠海","北京","Mon");
    MC.FindRoundWays("珠海","北京","Mon","Wes");
    MC.FindMultiWays("北京","上海","广州","Mon","Wes");

    //分别给自己和亲属添加订单
    for(int i=0;i<MC.flightinfos.size();i++)
        MC.AddOrder_dir(MC.flightinfos[i],"张三","410603XXXXXXXXXXXX","张三","410603XXXXXXXXXXXX",12,31,"Tur");

    for(int i=0;i<MC.trans1.size();i++)
        MC.AddOrder_trans(MC.trans1[i],MC.trans2[i],"张三","410603XXXXXXXXXXXX","张三儿子","4106XXXXXXXXXXXXXX",1,3,"Fri");


    MC.DeleteOrder_dir(2);
    MC.DeleteOrder_dir(3);
    MC.DeleteOrder_dir(6);

    for(int i=0;i<min(MC.round1.size(),MC.round2.size());i++)
        MC.AddOrder_rounds(MC.round1[i],MC.round2[i],"张三","410603XXXXXXXXXXXX","张三老婆","4106XXXXXXXXXXXXXX",11,27,"Wes");

    for(int i=0;i<min(MC.multi1.size(),MC.multi2.size());i++)
        MC.AddOrder_multis(MC.multi1[i],MC.multi2[i],"张三","410603XXXXXXXXXXXX","张三朋友","4106XXXXXXXXXXXXXX",7,11,"Thur");


    //查询订单
    MC.ShowOrders("张三老婆");

    //根据航班号查询航线信息
    MC.SearchFlight("FM9297");

    return a.exec();
}
